﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

//@author A0088027B
namespace EZXPNS
{
    public partial class IncomeForm : Form
    {
        MainForm mainform;
        public IncomeForm(MainForm frm)
        {
            InitializeComponent();
            mainform = frm;
        }

        private void IncomeForm_Load(object sender, EventArgs e)
        {
            //Display income list items
            StreamReader inputfile;
            inputfile = File.OpenText("../../IncomeList.txt");

            while (inputfile.EndOfStream == false)
            {
                string tempName = inputfile.ReadLine();
                string tempAmount = inputfile.ReadLine();
                string tempCategory = inputfile.ReadLine();
                string tempDate = inputfile.ReadLine();
                string tempPayment = inputfile.ReadLine();

                ListViewItem lvi = new ListViewItem(tempName);
                lvi.SubItems.Add(tempAmount);
                lvi.SubItems.Add(tempCategory);
                lvi.SubItems.Add(tempDate);
                lvi.SubItems.Add(tempPayment);
                listView1.Items.Add(lvi);
            }
            inputfile.Close();

            //Load cateogory list
            StreamReader inputfile2;

            inputfile2 = File.OpenText("../../IncomeCategory.txt");

            while (inputfile2.EndOfStream == false)
            {
                string tempCategory = inputfile2.ReadLine();
                Category_comboBox.Items.Add(tempCategory);
                IncomeCategory.IncomeItems.Add(tempCategory);
            }
            inputfile2.Close();

            //Set disabled buttons
            Done_Edit_Button.Enabled = false;
            Undo_Button.Enabled = false;

            //Clear undo list
            EzXpns._undoIndex.Clear();
            EzXpns._undoList.Clear();
            EzXpns._commands.Clear();

            //Set Maximum date of datetimepicker to be today.
            DateTimePicker.MaxDate = DateTime.Today;
        }

        private void Add_Button_Click(object sender, EventArgs e)
        {
            try
            {
                //Change Payment
                switch (Payment_comboBox.Text)
                {
                    case "Credit":
                        Payment.Credit += decimal.Parse(Amount_TextBox.Text);
                        break;
                    case "Debit":
                        Payment.Debit += decimal.Parse(Amount_TextBox.Text);
                        break;
                    case "Cash":
                        Payment.Cash += decimal.Parse(Amount_TextBox.Text);
                        break;
                    case "Ezlink":
                        Payment.Ezlink += decimal.Parse(Amount_TextBox.Text);
                        break;
                    default:
                        Payment.Others += decimal.Parse(Amount_TextBox.Text);
                        break;
                }

                Payment.UpdatePayment();

                //Record Undo information
                EzXpns._commands.Push("ADD");
                EzXpns._undoIndex.Push(EzXpns._incomeList.Count);

                //Write to Data Storage
                StreamWriter outputfile;
                outputfile = File.AppendText("../../IncomeList.txt");

                outputfile.WriteLine(Name_TextBox.Text);
                outputfile.WriteLine(Amount_TextBox.Text);
                outputfile.WriteLine(Category_comboBox.Text);
                DateTime dt = DateTimePicker.Value;
                outputfile.WriteLine(dt.ToString());
                outputfile.WriteLine(Payment_comboBox.Text);

                outputfile.Close();

                //Add to _incomeList
                Item newItem = new Item();
                newItem.Name = Name_TextBox.Text;
                newItem.Amount = decimal.Parse(Amount_TextBox.Text);
                newItem.Category = Category_comboBox.Text;
                newItem.Date = DateTimePicker.Value.ToString();
                newItem.Payment = Payment_comboBox.Text;

                EzXpns._incomeList.Add(newItem);

                //Display on listView
                ListViewItem lvi = new ListViewItem(Name_TextBox.Text);
                lvi.SubItems.Add(Amount_TextBox.Text);
                lvi.SubItems.Add(Category_comboBox.Text);
                lvi.SubItems.Add(DateTimePicker.Value.ToString());
                lvi.SubItems.Add(Payment_comboBox.Text);
                listView1.Items.Add(lvi);


                //Clear textboxs
                Name_TextBox.Text = "";
                Amount_TextBox.Text = "";
                Category_comboBox.Text = "";
                DateTimePicker.Value = DateTime.Today;
                Payment_comboBox.Text = "";

                //Change focus
                Name_TextBox.Focus();

                MessageBox.Show("Item added!");

                //Enable Boxes
                Undo_Button.Enabled = true;
                Done_Edit_Button.Enabled = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void Delete_Button_Click(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count == 0)
            {
                MessageBox.Show("No item is selected!");
                return;
            }

            try
            {
                //Change Payment
                switch (listView1.SelectedItems[0].SubItems[4].Text)
                {
                    case "Credit":
                        Payment.Credit -= decimal.Parse(listView1.SelectedItems[0].SubItems[1].Text);
                        break;
                    case "Debit":
                        Payment.Debit -= decimal.Parse(listView1.SelectedItems[0].SubItems[1].Text);
                        break;
                    case "Cash":
                        Payment.Cash -= decimal.Parse(listView1.SelectedItems[0].SubItems[1].Text);
                        break;
                    case "Ezlink":
                        Payment.Ezlink -= decimal.Parse(listView1.SelectedItems[0].SubItems[1].Text);
                        break;
                    default:
                        Payment.Others -= decimal.Parse(listView1.SelectedItems[0].SubItems[1].Text);
                        break;
                }

                Payment.UpdatePayment();

                //Record Undo information
                EzXpns._undoIndex.Push(listView1.SelectedItems[0].Index);
                EzXpns._undoList.Push(EzXpns._incomeList[listView1.SelectedItems[0].Index]);
                EzXpns._commands.Push("DEL");

                //Delete item from _incomeList
                EzXpns._incomeList.RemoveAt(listView1.SelectedItems[0].Index);

                //Delete item from listView
                listView1.SelectedItems[0].Remove();

                //Refresh Data Storage
                EzXpns.SaveIncome();

                MessageBox.Show("Item deleted!");

                //Enable button
                Undo_Button.Enabled = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        //@author A0083726Y
        private void Edit_Button_Click(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count == 0)
            {
                MessageBox.Show("No item is selected!");
                return;
            }

            //Record Undo information
            EzXpns._undoIndex.Push(listView1.SelectedItems[0].Index);
            EzXpns._undoList.Push(EzXpns._incomeList[listView1.SelectedItems[0].Index]);
            EzXpns._commands.Push("EDIT");

            //Edit item 
            MessageBox.Show("Please change related information!");

            //Display information on textboxs
            Name_TextBox.Text = listView1.SelectedItems[0].SubItems[0].Text;
            Amount_TextBox.Text = listView1.SelectedItems[0].SubItems[1].Text;
            Category_comboBox.Text = listView1.SelectedItems[0].SubItems[2].Text;
            DateTimePicker.Value = DateTime.Parse(listView1.SelectedItems[0].SubItems[3].Text);
            Payment_comboBox.Text = listView1.SelectedItems[0].SubItems[4].Text;

            Done_Edit_Button.Enabled = true;
            Add_Button.Enabled = false;
            Delete_Button.Enabled = false;
            Undo_Button.Enabled = false;
            Edit_Button.Enabled = false;

            Done_Edit_Button.Focus();
        }

        private void Done_Edit_Button_Click(object sender, EventArgs e)
        {
            try
            {
                //Change Payment upon deletion of old data
                switch (listView1.SelectedItems[0].SubItems[4].Text)
                {
                    case "Credit":
                        Payment.Credit -= decimal.Parse(listView1.SelectedItems[0].SubItems[1].Text);
                        break;
                    case "Debit":
                        Payment.Debit -= decimal.Parse(listView1.SelectedItems[0].SubItems[1].Text);
                        break;
                    case "Cash":
                        Payment.Cash -= decimal.Parse(listView1.SelectedItems[0].SubItems[1].Text);
                        break;
                    case "Ezlink":
                        Payment.Ezlink -= decimal.Parse(listView1.SelectedItems[0].SubItems[1].Text);
                        break;
                    default:
                        Payment.Others -= decimal.Parse(listView1.SelectedItems[0].SubItems[1].Text);
                        break;
                }

                //Delete then read item to _incomeList
                Item newItem = new Item();
                newItem.Name = Name_TextBox.Text;
                newItem.Amount = decimal.Parse(Amount_TextBox.Text);
                newItem.Category = Category_comboBox.Text;
                newItem.Date = DateTimePicker.Value.ToString();
                newItem.Payment = Payment_comboBox.Text;

                EzXpns._incomeList.RemoveAt(listView1.SelectedItems[0].Index);
                EzXpns._incomeList.Insert(listView1.SelectedItems[0].Index, newItem);

                //Display new item on listView
                listView1.SelectedItems[0].SubItems[0].Text = Name_TextBox.Text;
                listView1.SelectedItems[0].SubItems[1].Text = Amount_TextBox.Text;
                listView1.SelectedItems[0].SubItems[2].Text = Category_comboBox.Text;
                listView1.SelectedItems[0].SubItems[3].Text = DateTimePicker.Value.ToString();
                listView1.SelectedItems[0].SubItems[4].Text = Payment_comboBox.Text;

                //Change Payment upon addtion of new item
                switch (Payment_comboBox.Text)
                {
                    case "Credit":
                        Payment.Credit += decimal.Parse(Amount_TextBox.Text);
                        break;
                    case "Debit":
                        Payment.Debit += decimal.Parse(Amount_TextBox.Text);
                        break;
                    case "Cash":
                        Payment.Cash += decimal.Parse(Amount_TextBox.Text);
                        break;
                    case "Ezlink":
                        Payment.Ezlink += decimal.Parse(Amount_TextBox.Text);
                        break;
                    default:
                        Payment.Others += decimal.Parse(Amount_TextBox.Text);
                        break;
                }

                //Refresh Data Storage
                Payment.UpdatePayment();
                EzXpns.SaveIncome();

                MessageBox.Show("Item edited!");

                //Clear textboxs
                Name_TextBox.Text = "";
                Amount_TextBox.Text = "";
                Category_comboBox.Text = "";
                DateTimePicker.Value = DateTime.Today;
                Payment_comboBox.Text = "";

                //Change focus
                Name_TextBox.Focus();

                //Set buttons
                Done_Edit_Button.Enabled = false;
                Undo_Button.Enabled = true;
                Add_Button.Enabled = true;
                Delete_Button.Enabled = true;
                Edit_Button.Enabled = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        
        //@author A0085749L
        private void Undo_Button_Click(object sender, EventArgs e)
        {
            try
            {
                switch (EzXpns._commands.Peek())
                {
                    case "ADD":
                        //Change Payment
                        switch (EzXpns._incomeList[EzXpns._undoIndex.Peek()].Payment)
                        {
                            case "Credit":
                                Payment.Credit -= EzXpns._incomeList[EzXpns._undoIndex.Peek()].Amount;
                                break;
                            case "Debit":
                                Payment.Debit -= EzXpns._incomeList[EzXpns._undoIndex.Peek()].Amount;
                                break;
                            case "Cash":
                                Payment.Cash -= EzXpns._incomeList[EzXpns._undoIndex.Peek()].Amount;
                                break;
                            case "Ezlink":
                                Payment.Ezlink -= EzXpns._incomeList[EzXpns._undoIndex.Peek()].Amount;
                                break;
                            default:
                                Payment.Others -= EzXpns._incomeList[EzXpns._undoIndex.Peek()].Amount;
                                break;
                        }
                        //Delete item from _incomeList
                        EzXpns._incomeList.RemoveAt(EzXpns._undoIndex.Peek());

                        //Delete item from listView
                        listView1.Items[EzXpns._undoIndex.Peek()].Remove();

                        //Pop the stack
                        EzXpns._undoIndex.Pop();
                        EzXpns._commands.Pop();

                        //Refresh Data Storage
                        EzXpns.SaveIncome();
                        Payment.UpdatePayment();

                        MessageBox.Show("Undo Addition done!");
                        break;
                    case "DEL":
                        //Change Payment
                        switch (EzXpns._undoList.Peek().Payment)
                        {
                            case "Credit":
                                Payment.Credit += EzXpns._undoList.Peek().Amount;
                                break;
                            case "Debit":
                                Payment.Debit += EzXpns._undoList.Peek().Amount;
                                break;
                            case "Cash":
                                Payment.Cash += EzXpns._undoList.Peek().Amount;
                                break;
                            case "Ezlink":
                                Payment.Ezlink += EzXpns._undoList.Peek().Amount;
                                break;
                            default:
                                Payment.Others += EzXpns._undoList.Peek().Amount;
                                break;
                        }

                        //Add back the item to _incomeList
                        EzXpns._incomeList.Insert(EzXpns._undoIndex.Peek(), EzXpns._undoList.Peek());

                        //Add back the item to listView
                        ListViewItem lvi = new ListViewItem(EzXpns._undoList.Peek().Name);
                        lvi.SubItems.Add(EzXpns._undoList.Peek().Amount.ToString());
                        lvi.SubItems.Add(EzXpns._undoList.Peek().Category);
                        lvi.SubItems.Add(EzXpns._undoList.Peek().Date);
                        lvi.SubItems.Add(EzXpns._undoList.Peek().Payment);
                        listView1.Items.Insert(EzXpns._undoIndex.Peek(), lvi);

                        //Refresh Data Storage
                        EzXpns.SaveIncome();
                        Payment.UpdatePayment();

                        //Pop the stack
                        EzXpns._undoIndex.Pop();
                        EzXpns._commands.Pop();
                        EzXpns._undoList.Pop();

                        MessageBox.Show("Undo Deletion done!");
                        break;
                    case "EDIT":
                        //Change Payment upon deletion of edited data
                        switch (EzXpns._incomeList[EzXpns._undoIndex.Peek()].Payment)
                        {
                            case "Credit":
                                Payment.Credit -= EzXpns._incomeList[EzXpns._undoIndex.Peek()].Amount;
                                break;
                            case "Debit":
                                Payment.Debit -= EzXpns._incomeList[EzXpns._undoIndex.Peek()].Amount;
                                break;
                            case "Cash":
                                Payment.Cash -= EzXpns._incomeList[EzXpns._undoIndex.Peek()].Amount;
                                break;
                            case "Ezlink":
                                Payment.Ezlink -= EzXpns._incomeList[EzXpns._undoIndex.Peek()].Amount;
                                break;
                            default:
                                Payment.Others -= EzXpns._incomeList[EzXpns._undoIndex.Peek()].Amount;
                                break;
                        }
                        //Delete edited item and add original item to _incomeList
                        EzXpns._incomeList.RemoveAt(EzXpns._undoIndex.Peek());
                        EzXpns._incomeList.Insert(EzXpns._undoIndex.Peek(), EzXpns._undoList.Peek());

                        //Delete edited item and add original item to listView
                        listView1.Items[EzXpns._undoIndex.Peek()].Remove();
                        ListViewItem lvi2 = new ListViewItem(EzXpns._undoList.Peek().Name);
                        lvi2.SubItems.Add(EzXpns._undoList.Peek().Amount.ToString());
                        lvi2.SubItems.Add(EzXpns._undoList.Peek().Category);
                        lvi2.SubItems.Add(EzXpns._undoList.Peek().Date);
                        lvi2.SubItems.Add(EzXpns._undoList.Peek().Payment);
                        listView1.Items.Insert(EzXpns._undoIndex.Peek(), lvi2);

                        //Change Payment upon adding back of original data
                        switch (EzXpns._undoList.Peek().Payment)
                        {
                            case "Credit":
                                Payment.Credit += EzXpns._undoList.Peek().Amount;
                                break;
                            case "Debit":
                                Payment.Debit += EzXpns._undoList.Peek().Amount;
                                break;
                            case "Cash":
                                Payment.Cash += EzXpns._undoList.Peek().Amount;
                                break;
                            case "Ezlink":
                                Payment.Ezlink += EzXpns._undoList.Peek().Amount;
                                break;
                            default:
                                Payment.Others += EzXpns._undoList.Peek().Amount;
                                break;
                        }
                        //Refresh Data Storage
                        EzXpns.SaveIncome();
                        Payment.UpdatePayment();

                        //Pop the stack
                        EzXpns._undoIndex.Pop();
                        EzXpns._commands.Pop();
                        EzXpns._undoList.Pop();

                        MessageBox.Show("Undo Edition done!");
                        break;
                    default: break;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            if (EzXpns._commands.Count == 0)
                Undo_Button.Enabled = false;
        }

        //@author A0090998H
        private void AddCategory_Button_Click(object sender, EventArgs e)
        {
            CategoryForm _categoryForm = new CategoryForm(this);
            _categoryForm.ShowDialog();
        }

        private void IncomeForm_Closing(object sender, FormClosingEventArgs e)
        {
            //Update alert information current monthly income display on the main form
            mainform.AlertLabel.Text = EzXpns.Alert();

            decimal totalIncome = 0m, curMonthIncome = 0m;
            DateTime dtNow = DateTime.Now, temp;
            int tempMonth, tempYear, curMonth = dtNow.Month, curYear = dtNow.Year;

            for (int i = 0; i < EzXpns._incomeList.Count; i++)
            {
                totalIncome += EzXpns._incomeList[i].Amount;
                temp = Convert.ToDateTime(EzXpns._incomeList[i].Date);
                tempMonth = temp.Month;
                tempYear = temp.Year;
                if (tempMonth == curMonth && tempYear == curYear)
                    curMonthIncome += EzXpns._incomeList[i].Amount;
            }
            mainform.currentMonthlyIncome.Text = "S$" + curMonthIncome.ToString();

            decimal totalExpense = 0m;
            for (int i = 0; i < EzXpns._expenseList.Count; i++)
            {
                totalExpense += EzXpns._expenseList[i].Amount;
            }

            StreamReader inputfile4;
            inputfile4 = File.OpenText("../../GoalSaving.txt");
            decimal goal = decimal.Parse(inputfile4.ReadLine());
            inputfile4.Close();

            if (totalExpense > totalIncome)
                mainform.AlertLabel.ForeColor = Color.Red;
            else if ((totalIncome - totalExpense) < goal * 0.2m)
                mainform.AlertLabel.ForeColor = Color.Orange;
            else if ((totalIncome - totalExpense) < goal * 0.5m)
                mainform.AlertLabel.ForeColor = Color.YellowGreen;
            else if ((totalIncome - totalExpense) < goal * 0.8m)
                mainform.AlertLabel.ForeColor = Color.Green;
            else if ((totalIncome - totalExpense) < goal)
                mainform.AlertLabel.ForeColor = Color.Blue;
            else
                mainform.AlertLabel.ForeColor = Color.Purple;

            //progressbar
            if (totalExpense > totalIncome)
            {
                mainform.tenpercent.BackColor = Color.Red;
                mainform.twentypercent.BackColor = Color.Red;
                mainform.thirtypercent.BackColor = Color.Red;
                mainform.fortypercent.BackColor = Color.Red;
                mainform.fiftypercent.BackColor = Color.Red;
                mainform.sixtypercent.BackColor = Color.Red;
                mainform.seventypercent.BackColor = Color.Red;
                mainform.eightypercent.BackColor = Color.Red;
                mainform.ninetypercent.BackColor = Color.Red;
                mainform.hundredpercent.BackColor = Color.Red;
            }
            else
            {
                if ((totalIncome - totalExpense) >= goal)
                {
                    mainform.tenpercent.BackColor = Color.Green;
                    mainform.twentypercent.BackColor = Color.Green;
                    mainform.thirtypercent.BackColor = Color.Green;
                    mainform.fortypercent.BackColor = Color.Green;
                    mainform.fiftypercent.BackColor = Color.Green;
                    mainform.sixtypercent.BackColor = Color.Green;
                    mainform.seventypercent.BackColor = Color.Green;
                    mainform.eightypercent.BackColor = Color.Green;
                    mainform.ninetypercent.BackColor = Color.Green;
                    mainform.hundredpercent.BackColor = Color.Green;
                }
                else if ((totalIncome - totalExpense) > goal * 0.9m)
                {
                    mainform.tenpercent.BackColor = Color.Green;
                    mainform.twentypercent.BackColor = Color.Green;
                    mainform.thirtypercent.BackColor = Color.Green;
                    mainform.fortypercent.BackColor = Color.Green;
                    mainform.fiftypercent.BackColor = Color.Green;
                    mainform.sixtypercent.BackColor = Color.Green;
                    mainform.seventypercent.BackColor = Color.Green;
                    mainform.eightypercent.BackColor = Color.Green;
                    mainform.ninetypercent.BackColor = Color.Green;
                    mainform.hundredpercent.BackColor = SystemColors.Control;
                }
                else if ((totalIncome - totalExpense) > goal * 0.8m)
                {
                    mainform.tenpercent.BackColor = Color.Green;
                    mainform.twentypercent.BackColor = Color.Green;
                    mainform.thirtypercent.BackColor = Color.Green;
                    mainform.fortypercent.BackColor = Color.Green;
                    mainform.fiftypercent.BackColor = Color.Green;
                    mainform.sixtypercent.BackColor = Color.Green;
                    mainform.seventypercent.BackColor = Color.Green;
                    mainform.eightypercent.BackColor = Color.Green;
                    mainform.ninetypercent.BackColor = SystemColors.Control;
                    mainform.hundredpercent.BackColor = SystemColors.Control;
                }
                else if ((totalIncome - totalExpense) > goal * 0.7m)
                {
                    mainform.tenpercent.BackColor = Color.Green;
                    mainform.twentypercent.BackColor = Color.Green;
                    mainform.thirtypercent.BackColor = Color.Green;
                    mainform.fortypercent.BackColor = Color.Green;
                    mainform.fiftypercent.BackColor = Color.Green;
                    mainform.sixtypercent.BackColor = Color.Green;
                    mainform.seventypercent.BackColor = Color.Green;
                    mainform.eightypercent.BackColor = SystemColors.Control;
                    mainform.ninetypercent.BackColor = SystemColors.Control;
                    mainform.hundredpercent.BackColor = SystemColors.Control;
                }
                else if ((totalIncome - totalExpense) > goal * 0.6m)
                {
                    mainform.tenpercent.BackColor = Color.Green;
                    mainform.twentypercent.BackColor = Color.Green;
                    mainform.thirtypercent.BackColor = Color.Green;
                    mainform.fortypercent.BackColor = Color.Green;
                    mainform.fiftypercent.BackColor = Color.Green;
                    mainform.sixtypercent.BackColor = Color.Green;
                    mainform.seventypercent.BackColor = SystemColors.Control;
                    mainform.eightypercent.BackColor = SystemColors.Control;
                    mainform.ninetypercent.BackColor = SystemColors.Control;
                    mainform.hundredpercent.BackColor = SystemColors.Control;
                }
                else if ((totalIncome - totalExpense) > goal * 0.5m)
                {
                    mainform.tenpercent.BackColor = Color.Green;
                    mainform.twentypercent.BackColor = Color.Green;
                    mainform.thirtypercent.BackColor = Color.Green;
                    mainform.fortypercent.BackColor = Color.Green;
                    mainform.fiftypercent.BackColor = Color.Green;
                    mainform.sixtypercent.BackColor = SystemColors.Control;
                    mainform.seventypercent.BackColor = SystemColors.Control;
                    mainform.eightypercent.BackColor = SystemColors.Control;
                    mainform.ninetypercent.BackColor = SystemColors.Control;
                    mainform.hundredpercent.BackColor = SystemColors.Control;
                }
                else if ((totalIncome - totalExpense) > goal * 0.4m)
                {
                    mainform.tenpercent.BackColor = Color.Green;
                    mainform.twentypercent.BackColor = Color.Green;
                    mainform.thirtypercent.BackColor = Color.Green;
                    mainform.fortypercent.BackColor = Color.Green;
                    mainform.fiftypercent.BackColor = SystemColors.Control;
                    mainform.sixtypercent.BackColor = SystemColors.Control;
                    mainform.seventypercent.BackColor = SystemColors.Control;
                    mainform.eightypercent.BackColor = SystemColors.Control;
                    mainform.ninetypercent.BackColor = SystemColors.Control;
                    mainform.hundredpercent.BackColor = SystemColors.Control;
                }
                else if ((totalIncome - totalExpense) > goal * 0.3m)
                {
                    mainform.tenpercent.BackColor = Color.Green;
                    mainform.twentypercent.BackColor = Color.Green;
                    mainform.thirtypercent.BackColor = Color.Green;
                    mainform.fortypercent.BackColor = SystemColors.Control;
                    mainform.fiftypercent.BackColor = SystemColors.Control;
                    mainform.sixtypercent.BackColor = SystemColors.Control;
                    mainform.seventypercent.BackColor = SystemColors.Control;
                    mainform.eightypercent.BackColor = SystemColors.Control;
                    mainform.ninetypercent.BackColor = SystemColors.Control;
                    mainform.hundredpercent.BackColor = SystemColors.Control;
                }
                else if ((totalIncome - totalExpense) > goal * 0.2m)
                {
                    mainform.tenpercent.BackColor = Color.Green;
                    mainform.twentypercent.BackColor = Color.Green;
                    mainform.thirtypercent.BackColor = SystemColors.Control;
                    mainform.fortypercent.BackColor = SystemColors.Control;
                    mainform.fiftypercent.BackColor = SystemColors.Control;
                    mainform.sixtypercent.BackColor = SystemColors.Control;
                    mainform.seventypercent.BackColor = SystemColors.Control;
                    mainform.eightypercent.BackColor = SystemColors.Control;
                    mainform.ninetypercent.BackColor = SystemColors.Control;
                    mainform.hundredpercent.BackColor = SystemColors.Control;
                }
                else if ((totalIncome - totalExpense) >= goal * 0.1m)
                {
                    mainform.tenpercent.BackColor = Color.Green;
                    mainform.twentypercent.BackColor = SystemColors.Control;
                    mainform.thirtypercent.BackColor = SystemColors.Control;
                    mainform.fortypercent.BackColor = SystemColors.Control;
                    mainform.fiftypercent.BackColor = SystemColors.Control;
                    mainform.sixtypercent.BackColor = SystemColors.Control;
                    mainform.seventypercent.BackColor = SystemColors.Control;
                    mainform.eightypercent.BackColor = SystemColors.Control;
                    mainform.ninetypercent.BackColor = SystemColors.Control;
                    mainform.hundredpercent.BackColor = SystemColors.Control;
                }
                else
                {
                    mainform.tenpercent.BackColor = SystemColors.Control;
                    mainform.twentypercent.BackColor = SystemColors.Control;
                    mainform.thirtypercent.BackColor = SystemColors.Control;
                    mainform.fortypercent.BackColor = SystemColors.Control;
                    mainform.fiftypercent.BackColor = SystemColors.Control;
                    mainform.sixtypercent.BackColor = SystemColors.Control;
                    mainform.seventypercent.BackColor = SystemColors.Control;
                    mainform.eightypercent.BackColor = SystemColors.Control;
                    mainform.ninetypercent.BackColor = SystemColors.Control;
                    mainform.hundredpercent.BackColor = SystemColors.Control;
                }
            }
        }

        private void Exit_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Confirm exit?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (result == DialogResult.Yes)
                this.Close();

            else
            {
                //do nothing}
            };
        }
    }
}
